# Contributor:
# Maintainer: Paul Morgan <jumanjiman@gmail.com>
pkgname=editorconfig
_pkgname=$pkgname-core-c
pkgver=0.12.3
_testname=editorconfig-core-test
_testver=0.12
pkgrel=1
pkgdesc="EditorConfig core library written in C (for use by plugins supporting EditorConfig parsing)"
url="https://github.com/editorconfig/editorconfig-core-c"
arch="all"
license="BSD-2-Clause"
makedepends="cmake pcre2-dev"
subpackages="lib$pkgname:libs $pkgname-static $pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/editorconfig/$_pkgname/archive/v$pkgver.tar.gz
	https://github.com/editorconfig/$_testname/archive/v$_testver.tar.gz
	disable-failing-test.patch
	"
builddir="$srcdir/$_pkgname-$pkgver"

prepare() {
	# Tests are taken from a github release tarball so place them in the tree
	rmdir tests
	mv ../$_testname-$_testver tests
	default_prepare
}

build() {
	cmake . \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_C_FLAGS_MINSIZEREL="$CFLAGS" \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_DOCUMENTATION=False
	make
}

check() {
	make test
}

package() {
	make install DESTDIR="$pkgdir"

	# Remove symlink to editorconfig-$pkgver.
	rm -f "$pkgdir/usr/bin/$pkgname"
	mv -f "$pkgdir/usr/bin/$pkgname-$pkgver" "$pkgdir/usr/bin/$pkgname"
}

static() {
	depends=""
	pkgdesc="$pkgdesc (static library)"
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/*.a "$subpkgdir"/usr/lib
}

sha512sums="4a17cd6317bd45f8b0131070165d852569d020f1cf74e72b44057b97672184b4992aee54aae6e3222c669fdce8bb6b1f3482235e6518acffcef05e1d74087e6e  editorconfig-0.12.3.tar.gz
6a6334ad9de88062eab2de8c7dee60e45766cd2657cf41daf9fff6a3bc8ba3f9c9b9629d0c189d2127f6c8e615d0e8bd401e8e294f3f2c02cbd6fe452ca15e7c  v0.12.tar.gz
dbbd15f1559cf3fd03d8cfbcd122276c2f054d373e4a1ac0a5c867768d9f5ae3847bffb64e7109d816ed1c1934968b88cd690bc9429be1876bcf69df2eb3e62d  disable-failing-test.patch"
